<?php
$objXajax->registerFunction("frmlistbook_load");
$objXajax->registerFunction("frmlistbook_productDetail");

function frmlistbook_load($status="",$dateFrom='',$dateTo=''){     

   global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $addPath = '_'.$reporttype;
    $dateFrom = $dateFrom==''?SYSTEM_DATE  : $dateFrom;
    $dateTo = $dateTo==''?SYSTEM_DATE  : $dateTo;
    $datasum = array();
    $arrData = frmlistbook_createArray($status,$dateFrom,$dateTo);    
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/main_listbook_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
     $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('frmlistbook_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmlistbook_tbl');");  
    $objResponse->addScript('changeWaiting(1);');                      
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax      
}

function frmlistbook_createArray($status,$dateFrom,$dateTo){
    global $objDbUpdate,$tbl_postfix;
    $addCond= '';
    if($status!=''){
       $addCond=" and flg_process = '$status' "; 
    }   
    $sql = " select h.*,r.name as roomname from tbl_customer_book_room$tbl_postfix as h left join tbl_room_type$tbl_postfix r on h.room_type_id = r.id  where     datediff('$dateFrom',h.date_created)<=0 and datediff('$dateTo',h.date_created)>=0 $addCond";//
     $arr = $objDbUpdate->GetArray($sql);
    return  $arr  ;
} 

function frmlistbook_productDetail($generate_id){
    global $objDbUpdate,$lang,$tbl_postfix,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $sql = " select name as productname,num as num,price as price from tbl_history_product$tbl_postfix where generate_id = '$generate_id'  ";//
   // echo $sql; die();
     $arr = $objDbUpdate->GetArray($sql);
     $count = count($arr);
     $pricesum = 0;
     for($i=0;$i<$count;$i++){
          $pricesum  += (int)$arr[$i]['price'] ;
     }
     $datasum[0]['price']= $pricesum;
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/main_listbook_productdetail_grid.html');
    $oTbs->MergeBlock('blk_data', $arr); 
    $oTbs->MergeBlock('blk_data_sum', $datasum); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('frmlistbook_productDetail', 'innerHTML', $oTbs->Source);
    $objResponse->addScript("$('#frmlistbook_productDetail').dialog('open');");
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax             
    
} 

# end region process data
?>
